package com.security.config.security.authentication.common;

import com.security.domain.bo.R;
import com.security.utils.ResponseUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 *  登录失败处理器
 *
 * @author DblSun
 */
@Component
public class MyLoginFailureHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request,
                                        HttpServletResponse response,
                                        AuthenticationException exception) throws IOException {
        ResponseUtil.sendResponse(response, R.error(HttpServletResponse.SC_UNAUTHORIZED, exception.getMessage()));
    }
}
